//
//  AppDelegate+LifeCircle.m
//  CommonProject
//
//  Created by dcr on 2017/8/19.
//  Copyright © 2017年 邓兆太. All rights reserved.
//

#import "AppDelegate+LifeCircle.h"

@implementation AppDelegate (LifeCircle)

- (void) applicationDidEnterBackground:(UIApplication *)application{
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}

- (void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
    application.applicationIconBadgeNumber = 0;
}

- (void) application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{
    DLog(@"didFailToRegisterForRemoteNotificationsWithError %@", error);
}

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
    DLog(@"didReceiveRemoteNotification");
}

- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
    
}

- (void) application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
    
}

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    //禁止横屏
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    if([url.description hasPrefix:@""]){
        return YES;
    }else{
        return NO;
    }
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
    //如果极简SDK不可用，会跳转支付宝钱包进行支付，需要将支付宝钱包的支付结果回传给SDK
    if([url.host isEqualToString:@"safepay"]){
        DLog(@"url host equal safepay");
    }
    //支付宝钱包快登授权返回 authCode
    if([url.host isEqualToString:@"alipayclient"]){
        DLog(@"url host equal alipayclient");
    }
    
    if([url.description hasPrefix:@"mingsi:"]){
        NSString *courseId = [[url.description componentsSeparatedByString:@"id="] lastObject];
        DLog(@"url description hasPrefix mingsi courseId = %@", courseId);
    }else{
        return NO;
    }
    return YES;
}

@end
